package com.gzyj.jtt808.v2013.protocol;

import com.gzyj.jtt808.utils.HexBytesUtil;
import com.gzyj.jtt808.v2011.enums.JT808TerminalResult;
import com.gzyj.jtt808.v2013.enums.BusinessDataType;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import com.gzyj.jtt808.v2013.Package;
import java.io.Serializable;

/**
 * @author lhj
 */

@Data
public class JTT808_0x0001 extends Package implements Serializable {

    private Integer ReplyMsgNum;//应答流水号
    private Integer ReplyMsgId;//应答 ID
    private JT808TerminalResult TerminalResult;//结果


    public JTT808_0x0001(){
        super(BusinessDataType.终端通用应答.getCode());
    }

    @Override
    public void encodeImpl(ByteBuf buf) {
        buf.writeShort(this.ReplyMsgNum);
        buf.writeShort(this.ReplyMsgId);
        buf.writeByte(this.TerminalResult.getCode());
    }

    @Override
    public JTT808_0x0001 decodeImpl(ByteBuf buf) {
        this.ReplyMsgNum=buf.readUnsignedShort();

        this.ReplyMsgId=buf.readUnsignedShort();
        byte[] temp= HexBytesUtil.readByOffset(buf,1);
        int code=Integer.parseInt(HexBytesUtil.bytesToHex(temp),16);
        this.TerminalResult= JT808TerminalResult.find(code);
        return this;
    }


}